/**
 * Created by wang on 18/2/7.
 */

$(document).ready(function(){
    $('.flicker-example').flicker();

    // 下拉加载  初始化
    $('.scroll-container').infiniteScroll({
        // options
        path: function(){ // 下一页动态地址拼装  相对地址 绝对地址都可以  参数可以自己随便加
            var dataId = $('.scroll-container').children(":last").attr("id");
            var keyword = $('#keyword').val();
            if(keyword){
                return "/api/home/nav/list?dataId="+dataId+"&title="+keyword;
            }
            return "/api/home/nav/list?dataId="+dataId;
        },
        append: true,
        responseType: "html",
        status : ".scroll-status" // 提示语
    });
    // 下一页加载完成回调
    var instance = InfiniteScroll.data(".scroll-container");
    instance.on("load",function(respond,path){
        var respond = respond.replace(/dataId\":(\d+),/g,"dataId\":\"$1\",");
        respond = $.parseJSON(respond);
        if(respond.errType=='0000'){

            var datas = respond.data.items;
            var html = '';
            for(var a=0;a<datas.length;a++){
                var data = datas[a].item;
                var da = new Date(data.publishTime);
                var year = da.getFullYear()+'年';
                var month = da.getMonth()+1+'月';
                var date = da.getDate()+'日';
                var dateFull = year+month+date;

                html += '<div class="column" id="'+data.dataId+'">'+
                    '<img src="'+data.img_url[0]+'" />'+
                    '<div class="text">'+
                    '<h1>'+
                    '<a target="_blank" href="/api/home/detail/'+data.dataId+'" class="textyc_sl">'+data.name+'</a>'+
                    '</h1>'+
                    '<span><a href="#">发布时间：'+dateFull+'</a></span>'+
                    '</div>'+
                    '<div class="clearfix"></div>'+
                    '</div>';
            }
        }
        $('.scroll-container').append(html);
        this.isLoading = false; //标识为append结束
    });
});